package com.example.springkotlin.uploadpic.domain

//import com.example.springkotlin.mybatis.UserDao
import com.example.springkotlin.mybatis.UserMapper
import com.example.springkotlin.util.FileUtil
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import javax.servlet.http.HttpServletRequest


@Service
class SavePicService{

    @Autowired
    lateinit var userDao: UserMapper

    fun insert(person: Person, request: HttpServletRequest?) {
        try{
            if (person.picFile?.size!! > 0) {
                println("检查到有文件被上传")
                // 将文件转换为文件地址
                FileUtil.deleteFile(request, person.picPath)
                val pic: String = FileUtil.upload(person?.picFile!!, request)
                println("拿到文件地址: $pic")
                person.picPath = pic
            }
        }catch (e:NullPointerException){
            println("文件可能是空的嘞")
        }finally {
            // 生成id
//        val a: Int = baseMapper.insert(emailDetail)
            println("------------------------:${person}")
            userDao.insert(person)
        }



    }
}